﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CCWin;

namespace SCCM
{
    public partial class PortManage : Skin_Mac
    {
        public PortManage()
        {
            InitializeComponent();
        }

        private void PortManage_Load(object sender, EventArgs e)
        {
            DataBase dataBase = new DataBase();
            skinDataGridView1.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter;
            this.skinDataGridView1.DataSource = dataBase.GetPortInfoTable();
            this.skinDataGridView1.Columns[0].HeaderText = "ID";
            this.skinDataGridView1.Columns[1].HeaderText = "变电站名称";
            this.skinDataGridView1.Columns[2].HeaderText = "变电站编号";
            this.skinDataGridView1.Columns[3].HeaderText = "开关室名称";
            this.skinDataGridView1.Columns[4].HeaderText = "开关室编号";
            this.skinDataGridView1.Columns[5].HeaderText = "开关柜名称";
            this.skinDataGridView1.Columns[6].HeaderText = "开关柜编号";
            
            //this.skinDataGridView1.data;
            this.skinDataGridView1.Refresh();
        }

       
        private void 更新ToolStripMenuItem_Click(object sender, EventArgs e)
        {
           // DataSet ds = (DataSet)this.skinDataGridView1.DataSource;
            DataBase db = new DataBase();
            db.clearPortInfo();

            for (int i = 0; i < skinDataGridView1.Rows.Count - 1; i++)
            {
                db.InsertPortInfo(skinDataGridView1.Rows[i]);
            }
            
            MessageBox.Show("信息已经更新");
            this.skinDataGridView1.DataSource = db.GetPortInfoTable();
            this.skinDataGridView1.Columns[0].HeaderText = "ID";
            this.skinDataGridView1.Columns[1].HeaderText = "变电站名称";
            this.skinDataGridView1.Columns[2].HeaderText = "变电站编号";
            this.skinDataGridView1.Columns[3].HeaderText = "开关室名称";
            this.skinDataGridView1.Columns[4].HeaderText = "开关室编号";
            this.skinDataGridView1.Columns[5].HeaderText = "开关柜名称";
            this.skinDataGridView1.Columns[6].HeaderText = "开关柜编号";
            //this.skinDataGridView1.data;
            this.skinDataGridView1.Refresh();
        }

        private void skinDataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (skinDataGridView1.CurrentCell.ColumnIndex == 0)
            {
                skinDataGridView1.CurrentCell.ReadOnly = true;
            }
            else
            {
                skinDataGridView1.CurrentCell.ReadOnly = false;
            }
        }
       
    }
}
